import React from 'react';
import * as asyncLoad from '../util/asyncLoad';
import { workflowPublicFiles } from '../constants/fileConfig';
import Loading from './Loading';
import { observer, inject } from "mobx-react/index";
import {toJS,observable,asMap} from 'mobx'
import {filterRequest4Forward,showAuthDialog} from "../util/secondAuthUtil";

@inject("globalStore","secondAuthStore")
export default class Forward extends React.Component {
    constructor() {
        super();
        this.state = { hasLoad: false };
    }
    componentDidMount() {
        const init = () => {
            const { WFForwardStore } = window.weaWorkflowPublic;
            const store = new WFForwardStore();
            this.setState({ hasLoad: true, store: store });
        }
        asyncLoad.asyncLoadModule('workflowPublic', workflowPublicFiles, init);
    }
    onClose = () => {
    }

    render() {
        const { hasLoad, store } = this.state;
        if (hasLoad) {
            const { forwardParams = {}, callBackActions = {} } = this.props;
            const { WfForward } = window.weaWorkflowPublic;
            const remark_list = this.props.globalStore.variableMap.get("remark_list") || (observable.map ? observable.map({}) : asMap({}));

            const {globalStore, secondAuthStore} = this.props;
            const {submitParam} = globalStore;
            const {workflowid, nodeid, requestid,f_weaver_belongto_userid,f_weaver_belongto_usertype} = submitParam;
            const secondAuthParam = {
                workflowid,
                nodeid,
                requestid,
                f_weaver_belongto_userid,
                f_weaver_belongto_usertype
            };

        	store.setShowForward(forwardParams, callBackActions)
            store.setRemarkList(remark_list)
			store.setSecondAuthParams(secondAuthParam, secondAuthStore, filterRequest4Forward, this.onClose, showAuthDialog);
            return (<WfForward ecId={`${this && this.props && this.props.ecId || ''}_WfForward@li9hf0`} wfForwardStore={store} globalStore={this.props.globalStore} />);
        } else {
            return (<Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@ypb089`} />);
        }
    }
}